package cn.edu.zsc.blms;

import cn.edu.zsc.blms.service.array.BookService;
import cn.edu.zsc.blms.service.array.IBookService;
import cn.edu.zsc.blms.service.array.IReaderService;
import cn.edu.zsc.blms.service.array.ReaderService;

import java.util.Scanner;

/**
 * @author 周易
 */

public class App {
    public static Scanner input;

    private final IBookService bookService;
    private final IReaderService readerService;

    public App(IBookService bookService,IReaderService readerService){
        this.bookService=bookService;
        this.readerService=readerService;
    }

    public static void main(String[] args){
        App app=new App(BookService.getSingleton(),ReaderService.getSingleton());
        app.run();
    }

    public void run(){
        input=new Scanner(System.in);
        //TODD:显示菜单，等待用户输入
        String systemMenuChoice;
        do {
            systemMenu();
            systemMenuChoice = input.nextLine();
            switch (systemMenuChoice) {
                case "0":
                    System.out.println("成功退出系统，欢迎再次使用！");
                    break;
                case "1":
                    String readerMenuChoice;
                    do {
                        readerMenu();
                        readerMenuChoice = input.nextLine();
                        switch (readerMenuChoice) {
                            case "0":
                                break;
                            case "1":
                                // TODO：添加读者
                                readerService.create();
                                break;
                            case "2":
                                // TODO: 禁用读者
                                readerService.disable();
                                break;
                            case "3":
                                // TODO: 编辑读者
                                readerService.update();
                                break;
                            case "4":
                                // TODO：查询读者
                                readerService.query();
                                break;
                            default:
                                System.out.println("输入非法，请输入正确的菜单编号！");
                        }
                    } while (!("0").equals(readerMenuChoice));
                    break;
                case "2":
                    String bookMenuChoice;
                    do {
                        bookMenu();
                        bookMenuChoice = input.nextLine();
                        switch (bookMenuChoice) {
                            case "0":
                                break;
                            case "1":
                                // TODO：添加图书
                                bookService.create();
                                break;
                            case "2":
                                // TODO: 废弃图书
                                bookService.disable();
                                break;
                            case "3":
                                // TODO: 编辑图书
                                bookService.update();
                                break;
                            case "4":
                                // TODO：查询图书
                                bookService.query();
                                break;
                            default:
                                System.out.println("输入非法，请输入正确的菜单编号！");
                        }
                    } while (!"0".equals(bookMenuChoice));
                    break;
                case "3":
                    String borrowingMenuChoice;
                    do {
                        borrowingMenu();
                        borrowingMenuChoice = input.nextLine();
                        switch (borrowingMenuChoice) {
                            case "0":
                                break;
                            case "1":
                                // TODO: 借阅图书
                                break;
                            case "2":
                                // TODO: 归还图书
                                break;
                            case "3":
                                // TODO: 查询记录
                                break;
                            default:
                                System.out.println("输入非法，请输入正确的菜单编号！");
                        }
                    } while (!"0".equals(borrowingMenuChoice));
                    break;
                default:
                    System.out.println("输入非法，请输入正确的菜单编号！");
            }
        } while (!"0".equals(systemMenuChoice));

        input.close();
    }

    /**
     * 输出系统管理菜单
     */
    public void systemMenu() {
        System.out.println("---------------------");
        System.out.println("    图书管理系统     ");
        System.out.println("---------------------");
        System.out.println("|   0...退出系统	|");
        System.out.println("|   1...读者管理	|");
        System.out.println("|   2...图书管理	|");
        System.out.println("|   3...借还图书	|");
        System.out.println("---------------------");
        System.out.print("请输入选项：");
    }

    /**
     * 输出读者管理菜单
     */
    public void readerMenu() {
        System.out.println("---------------------");
        System.out.println("    读者管理     ");
        System.out.println("---------------------");
        System.out.println("|   0...返回上级	|");
        System.out.println("|   1...添加读者	|");
        System.out.println("|   2...禁用读者	|");
        System.out.println("|   3...编辑读者	|");
        System.out.println("|   4...查询读者	|");
        System.out.println("---------------------");
        System.out.print("请输入选项：");
    }

    /**
     * 输出图书管理菜单
     */
    public void bookMenu() {
        System.out.println("---------------------");
        System.out.println("    图书管理     ");
        System.out.println("---------------------");
        System.out.println("|   0...返回上级	|");
        System.out.println("|   1...添加图书	|");
        System.out.println("|   2...废弃图书	|");
        System.out.println("|   3...编辑图书	|");
        System.out.println("|   4...查询图书	|");
        System.out.println("---------------------");
        System.out.print("请输入选项：");
    }

    /**
     * 输出借还图书菜单
     */
    public void borrowingMenu() {
        System.out.println("---------------------");
        System.out.println("    借还图书     ");
        System.out.println("---------------------");
        System.out.println("|   0...返回上级	|");
        System.out.println("|   1...借阅图书	|");
        System.out.println("|   2...归还图书	|");
        System.out.println("|   3...查询记录	|");
        System.out.println("---------------------");
        System.out.print("请输入选项：");
    }


}
